package com.ruoyi.system.service.impl;

import com.github.pagehelper.IPage;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.Equipment;
import com.ruoyi.system.domain.dto.EquipmentQueryDto;
import com.ruoyi.system.domain.vo.EquipmentVo;
import com.ruoyi.system.mapper.EquipmentMapper;
import com.ruoyi.system.service.IEquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class EquipmentServiceImpl implements IEquipmentService {

    @Autowired
    private EquipmentMapper equipmentMapper;

    @Override
    public Map getEquipmentList(EquipmentQueryDto dto) {
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        Page<Equipment> page = equipmentMapper.selectEquipmentList(dto);
        HashMap<Object, Object> map = new HashMap<>();
        map.put("data",page.getResult());
        map.put("total",page.getTotal());
        return map;
    }

    @Override
    public void save(Equipment equipment) {
        equipment.setCreateDate(new Date(System.currentTimeMillis()));
        equipment.setCreatePerson(SecurityUtils.getUserId()+"");
        equipmentMapper.insert(equipment);
    }

    @Override
    public void updea(Equipment equipment) {
        equipment.setUpdatePerson(SecurityUtils.getUserId()+"");
        equipment.setUpdateDate(new Date(System.currentTimeMillis()));
        equipmentMapper.updeat(equipment);
    }

    @Override
    public void changeEquipmentStatus(Equipment equipment) {
        equipmentMapper.changeEquipmentStatus(equipment.getId(),equipment.getStates());
    }

    @Override
    public void removeByIds(Long[] ids) {
        equipmentMapper.deleteByIds(ids);
    }

    @Override
    public List<EquipmentVo> getEquipmentVoList() {
        return equipmentMapper.selectEquipmentVoList();
    }
}
